/**
 * Created by IntelliJ IDEA
 *
 * @author zhengjie
 * @Date:2022/2/12 15:29
 * @Version 1.0
 */
package com.zj.ssm.aop;

import com.zj.ssm.mapper.LogMapper;
import com.zj.ssm.pojo.domain.Admin;
import com.zj.ssm.pojo.domain.LogData;
import com.zj.ssm.result.AjaxResult;
import org.aspectj.lang.JoinPoint;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.Arrays;
import java.util.Date;

public class HahaAop {

    @Autowired
    private LogMapper mapper;


    public void after(JoinPoint joinPoint, Log aaaLog, AjaxResult result){

        ServletRequestAttributes requestAttributes = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes();
        HttpServletRequest request = requestAttributes.getRequest();
        HttpServletResponse response = requestAttributes.getResponse();

        Admin admin = (Admin) request.getSession().getAttribute("admin");
        String ename = admin.getName();

        String    msg  = aaaLog.value();
        String    code = result.getMsg();
        String    addr = request.getRemoteAddr();
        Date      date = new Date();
        Object[]  data = joinPoint.getArgs();

        LogData logData = new LogData(null, ename, msg, code, addr, date.toString(), Arrays.toString(data));

        mapper.addLog(logData);
    }





}

